package com.fzc.rhinooffice.module.office;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fzc.rhinooffice.R;
import com.fzc.rhinooffice.common.SysApplication;
import com.fzc.rhinooffice.module.workbench.FileManagerActivity;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

/**
 * 办公
 * @author chao.liu
 *
 */

public class OfficeFragment extends Fragment {

	private View view;

	@ViewInject(R.id.rl_office_email)
	private RelativeLayout rl_office_email;

	@ViewInject(R.id.tv_email_unread)
	private TextView tv_email_unread;		//未读邮件

	@ViewInject(R.id.rl_office_notice)
	private RelativeLayout rl_office_notice;

	@ViewInject(R.id.tv_notice_unread)
	private TextView tv_notice_unread;		//未读通知

	@ViewInject(R.id.rl_office_tidings)
	private RelativeLayout rl_office_tidings;

	@ViewInject(R.id.tv_tidings_unread)
	private TextView tv_tidings_unread;		//未读新闻

	@ViewInject(R.id.rl_office_workflow)
	private RelativeLayout rl_office_workflow;

	@ViewInject(R.id.tv_office_workflow_unread)
	private TextView tv_office_workflow_unread;		//未读新闻

	@ViewInject(R.id.rl_office_personal_folders)
	private RelativeLayout rl_office_personal_folders;

	@ViewInject(R.id.tv_personal_folders_unread)
	private TextView tv_personal_folders_unread;		//未读新闻

	@ViewInject(R.id.rl_office_internal_sms)
	private RelativeLayout rl_office_internal_sms;

	@ViewInject(R.id.tv_internal_sms_unread)
	private TextView tv_internal_sms_unread;		//未读新闻

	@ViewInject(R.id.rl_office_positioning_sign)
	private RelativeLayout rl_office_positioning_sign;

	@ViewInject(R.id.tv_office_positioning_sign_unread)
	private TextView tv_office_positioning_sign_unread;		//未读新闻

	@ViewInject(R.id.rl_office_funding_schedule)
	private RelativeLayout rl_office_funding_schedule;

	@ViewInject(R.id.tv_office_funding_schedule_unread)
	private TextView tv_office_funding_schedule_unread;		//资金计划表
	
	private Intent mIntent;



	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
							 Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.fragment_office, container, false);
		ViewUtils.inject(this, view);
		return view;
	}


	@Override
	public void onResume() {
		super.onResume();
		initUI();
	}
	
	private void initUI(){
		
		if (SysApplication.email!=null && !"0".equals(SysApplication.email.email_sl)) {
			tv_email_unread.setVisibility(View.VISIBLE);
			tv_email_unread.setText(SysApplication.email.email_sl);
		} else {
			tv_email_unread.setVisibility(View.GONE);
		}
		
		if (SysApplication.email!=null && !"0".equals(SysApplication.notify.notify_sl)) {
			tv_notice_unread.setVisibility(View.VISIBLE);
			tv_notice_unread.setText(SysApplication.notify.notify_sl);
		} else {
			tv_notice_unread.setVisibility(View.GONE);
		}
		
		if (SysApplication.email!=null && !"0".equals(SysApplication.news.news_sl)) {
			tv_tidings_unread.setVisibility(View.VISIBLE);
			tv_tidings_unread.setText(SysApplication.news.news_sl);
		} else {
			tv_tidings_unread.setVisibility(View.GONE);
		}
		
		
	}
	
	@OnClick(R.id.rl_office_email)
	private void checkEmail(View v){
		if(mIntent==null){
			mIntent = new Intent();
		}
		mIntent.setClass(getActivity(), EmailListActivity.class);
		startActivity(mIntent);
	}

	@OnClick(R.id.rl_office_notice)
	private void checkNotice(View v){

		if(mIntent==null){
			mIntent = new Intent();
		}
		mIntent.setClass(getActivity(), NotifyListActivity.class);
		startActivity(mIntent);
	}

	@OnClick(R.id.rl_office_tidings)
	private void checkTidings(View v){

		if(mIntent==null){
			mIntent = new Intent();
		}
		mIntent.setClass(getActivity(),NewsListActivity.class);
		startActivity(mIntent);
	}

	@OnClick(R.id.ll_workflow)
	private void checkWrokflow(View v){

	}

	@OnClick(R.id.rl_office_internal_sms)
	private void smsOnclick(View v){
		if (mIntent == null) {
			mIntent = new Intent();
		}
		mIntent.setClass(getActivity(), SmsListActivity.class);
		startActivity(mIntent);
	}

	@OnClick(R.id.rl_office_personal_folders)
	private void fileFolderOnclick(View v){
		if (mIntent == null) {
			mIntent = new Intent();
		}
		mIntent.setClass(getActivity(), FileManagerActivity.class);
		startActivity(mIntent);
	}

}
